package com.geekaca.ssm.controller;

import com.geekaca.ssm.exception.BusinessException;
import com.geekaca.ssm.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex) {
        return new Result(ex.getCode(), ex.getMessage(), null);
    }

    //handler: 处理器参数指定 要处理的异常
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex) {
        //构造一个统一的接口数据格式对象，返回给前端
        //log 日志写文件，写DB
        return new Result(ex.getCode(), ex.getMessage(), null);
    }

}
